Similar to what has been done recently for DESKTOP_AUTOSTART_ID [1],
we need to get rid of this call to g_unsetenv() in the displays'
backends for X11 and Wayland, so that it's guarantee to happen any
thread is created, while still being accessible when needed.
Let's stash the value of this environment variable when loading the
GDK library, and provide a private method so that it can be retrieved
from the displays' backend when implementing gdk_display_make_default().
[1] https://gitlab.gnome.org/GNOME/gtk/commit/
22269902
Closes: https://gitlab.gnome.org/GNOME/gtk/issues/979
const char *theme,
int size);
+const gchar * gdk_get_startup_notification_id (void);
+
#endif /* __GDK__PRIVATE_H__ */
};
#endif
+
+#ifdef G_HAS_CONSTRUCTORS
+#ifdef G_DEFINE_CONSTRUCTOR_NEEDS_PRAGMA
+#pragma G_DEFINE_CONSTRUCTOR_PRAGMA_ARGS(stash_desktop_startup_notification_id)
+#endif
+G_DEFINE_CONSTRUCTOR(stash_desktop_startup_notification_id)
+#endif
+
+static gchar *startup_notification_id = NULL;
+
+static void
+stash_desktop_startup_notification_id (void)
+{
+ const char *desktop_startup_id;
+
+ desktop_startup_id = g_getenv ("DESKTOP_STARTUP_ID");
+ if (desktop_startup_id && *desktop_startup_id != '\0')
+ {
+ if (!g_utf8_validate (desktop_startup_id, -1, NULL))
+ g_warning ("DESKTOP_STARTUP_ID contains invalid UTF-8");
+ else
+ startup_notification_id = g_strdup (desktop_startup_id ? desktop_startup_id : "");
+ }
+
+ /* Clear the environment variable so it won't be inherited by
+ * child processes and confuse things.
+ */
+ g_unsetenv ("DESKTOP_STARTUP_ID");
+}
+
static gpointer
register_resources (gpointer dummy G_GNUC_UNUSED)
{
G_N_ELEMENTS (gdk_debug_keys));
}
#endif /* G_ENABLE_DEBUG */
+
+#ifndef G_HAS_CONSTRUCTORS
+ stash_desktop_startup_notification_id ();
+#endif
}
/*< private >
return display;
}
+/*< private >
+ *
+ * gdk_get_startup_notification_id
+ *
+ * Returns the original value of the DESKTOP_STARTUP_ID environment
+ * variable if it was defined and valid, or %NULL otherwise.
+ *
+ * Returns: (nullable) (transfer none): the original value of the
+ * DESKTOP_STARTUP_ID environment variable, or %NULL.
+ */
+const gchar *
+gdk_get_startup_notification_id (void)
+{
+ return startup_notification_id;
+}
+
/**
* SECTION:threads
* @Short_description: Functions for using GDK in multi-threaded programs
#include "wm-button-layout-translation.h"
+#include "gdk/gdk-private.h"
+
/**
* SECTION:wayland_interaction
* @Short_description: Wayland backend-specific functions
g_free (display_wayland->startup_notification_id);
display_wayland->startup_notification_id = NULL;
- startup_id = g_getenv ("DESKTOP_STARTUP_ID");
- if (startup_id && *startup_id != '\0')
- {
- if (!g_utf8_validate (startup_id, -1, NULL))
- g_warning ("DESKTOP_STARTUP_ID contains invalid UTF-8");
- else
- display_wayland->startup_notification_id = g_strdup (startup_id);
-
- /* Clear the environment variable so it won't be inherited by
- * child processes and confuse things.
- */
- g_unsetenv ("DESKTOP_STARTUP_ID");
- }
+ startup_id = gdk_get_startup_notification_id ();
+ if (startup_id)
+ display_wayland->startup_notification_id = g_strdup (startup_id);
}
static gboolean
g_free (display_x11->startup_notification_id);
display_x11->startup_notification_id = NULL;
- startup_id = g_getenv ("DESKTOP_STARTUP_ID");
- if (startup_id && *startup_id != '\0')
- {
- if (!g_utf8_validate (startup_id, -1, NULL))
- g_warning ("DESKTOP_STARTUP_ID contains invalid UTF-8");
- else
- gdk_x11_display_set_startup_notification_id (display, startup_id);
-
- /* Clear the environment variable so it won't be inherited by
- * child processes and confuse things.
- */
- g_unsetenv ("DESKTOP_STARTUP_ID");
- }
+ startup_id = gdk_get_startup_notification_id ();
+ if (startup_id)
+ gdk_x11_display_set_startup_notification_id (display, startup_id);
}
static void